<?php
/**
 * common model file Created by PhpStorm.
 * User: wumengmeng
 * Date: 2019/08/20
 * Time: 06:01
 */

namespace HiCommon\Model;

class Checkpoint extends Base
{
    
   // protected $table = 'checkpoint';
    protected $table = 'shop';
    
    protected $guarded = [];
    
    //public $timestamps = false;
    
    /**
     * 应该被调整为日期的属性
     *
     * @var array
     */
    protected $dates = [
    ];

    //一对一关联分类
    public function type()
    {
        return $this->hasOne(CheckpointType::class, 'id','type')
            ->select('id','title');
    }

    //一对多关联检测机构服务类型
    public function service_type()
    {
        return $this->hasMany(CheckpointServiceType::class, 'checkpoint_id','id')
            ->select('id','checkpoint_id','title','price');
    }
    //一对多关联开放日期
    public function make_day()
    {
        return $this->hasMany(CheckpointMakeDate::class, 'checkpoint_id','id')
            ->where('day','>=',date('Y-m-d',time()))
            ->select('id','checkpoint_id','day','am_time','am_num','am_order','pm_time','pm_num','pm_order');
    }

    //一对多关联车检费用
    public function outlay()
    {
        return $this->hasMany(CheckpointOutlay::class, 'checkpoint_id','id')
            ->select('id','checkpoint_id','title','pic_url');
    }

    /**
     * 获取状态对应的名称
     *
     * @return array
     * @author wumengmeng <wu_mengmeng@foxmail.com>
     */
    public function getStateAttribute($value)
    {
        switch ($value)
        {
            case 0:
                $res = ['id'=>0,'name'=>'草稿'];
                break;
            case 1:
                $res = ['id'=>1,'name'=>'待审核'];
                break;
            case 2:
                $res = ['id'=>2,'name'=>'通过'];
                break;
            case 3:
                $res = ['id'=>3,'name'=>'拒绝'];
                break;
            default:
                $res = ['id'=>-1,'name'=>'未知'];
        }
        return $res;
    }
    
        /**
         * 获取图片可用链接
         *
         * @return array
         * @author wumengmeng <wu_mengmeng@foxmail.com>
         */
        public function getLogoAttribute($value)
        {
            $arr_data = [
              'src'=>$value,
              'full_src'=>oss_full_url($value),
            ];
            return $arr_data;
        }
        
        /**
         * 扩展信息
         *
         * @return array
         * @author wumengmeng <wu_mengmeng@foxmail.com>
         */
        public function getExtendAttribute()
        {
            $s_created_at = $this->created_at;
            $arr_data = [
              'created_at'=>ymd_friendly_date($s_created_at),
            ];

            return $arr_data;
        }

    
  
}